package advanced;

import java.util.concurrent.CountDownLatch;

public class Test4 {

    public static void main3(String[] args) throws InterruptedException {

        CountDownLatch latch = new CountDownLatch(6);
        for(int i = 0; i < 6; i++){
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(3000);
                    System.out.println(Thread.currentThread().getName()+"到达终点!");
                    // 通知主线程该线程执行完了
                    latch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }
        // 等待所有线程执行完，就执行下面的语句
        latch.await();
        System.out.println("所有选手到达终点!");
    }
}
